package cn.xjt.controller;

import cn.xjt.pojo.User;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 内容：
 *
 * @author
 * @date 2020/9/25-14:31
 */

@RestController
public class AjaxController {

	@RequestMapping("/hh")
	public String test()
	{
		return "hello";
	}


	@RequestMapping("/h2")
	public void test2(String name, HttpServletResponse response) throws IOException {
		System.out.println("h2:param=>"+name);

		if("徐江涛".equals(name)){
			response.getWriter().print("true:"+name);
		}else{
			response.getWriter().print("false:"+name);
		}
	}

	@RequestMapping("/h3")
	public List<User> heool()
	{
		List<User> userList = new ArrayList<User>();

		userList.add(new User("徐江涛",18,"男"));
		userList.add(new User("胡丹露",18,"女"));
		userList.add(new User("胡丹露2",19,"女"));
		userList.add(new User("胡丹露3",20,"女"));


		return userList;
	}

	@RequestMapping("/l")
	public String login(String name,String pwd)
	{
		String msg="";
		//判断用户名是否输入正确，，admin应该是从数据库得到
		if(name!=null){
			if("admin".equals(name))
			{
				msg="OK";
			}else{
				msg="you input username is fail";
			}
		}
		//判断密码是否输入正确
		if(pwd!=null){
			if("123456".equals(pwd))
			{
				msg="OK";
			}else{
				msg="you input password is fail";
			}
		}
		System.out.println(name);
		System.out.println(pwd);
		return msg;
	}
}
